// project created on 01/14/2007 at 16:46
using System;

namespace frmDebugDesignerPoker
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			// Assume args is one..
			//string sFilename = "";
			//
			//foreach (string sOh in args)
			//	sFilename += sOh + " ";
			string sDirname = args[0];
			int i;
			string[] sLines;
			
			sDirname.Trim();
			
			Console.WriteLine("Starting processing in directory " + sDirname + "\r\nWill write to ./frmDebug.Designer.cs and ./frmDebug.cs ...");
			
			
			Console.WriteLine("===========================================");
			Console.WriteLine("  Processing frmDebug.Designer.cs ...");
			Console.WriteLine("===========================================");
			// Open the file..
			sLines = System.IO.File.ReadAllText(sDirname + "frmDebug.Designer.cs").Replace("\r", "").Split('\n');
			
			// Remove all lines that contain 'mnuIcon', and lines that fiddle with 'resources'...
			for (i = sLines.GetLowerBound(0); i <= sLines.GetUpperBound(0); i++)
			{
				if (!sLines[i].Contains("//"))
				{
					// mnuIcon reference?
					if (sLines[i].Contains("mnuIcon"))
					{
						sLines[i] = "";
						System.Console.WriteLine("(mnuIcon string search) Removed line #" + i.ToString());
					}
					
					// AutoCompleteMode || AutoCompleteSource?
					if (sLines[i].Contains("AutoCompleteMode") || sLines[i].Contains("AutoCompleteSource"))
					{
						sLines[i] = "";
						System.Console.WriteLine("(AutoCompleteMode/Source string search) Removed line #" + i.ToString());
					}
					
					// BalloonTip* ?
					if (sLines[i].Contains("BalloonTip"))
					{
						sLines[i] = "";
						System.Console.WriteLine("(*BalloonTip* string search) Removed line #" + i.ToString());
					}
					
					// Reference to the ever-broken 'resources'?
					if (sLines[i].Contains("resources"))
					{
						if (sLines[i].Contains("Icon") && sLines[i].Contains("GetObject"))
						{
							// Replace..
							sLines[i] = sLines[i].Substring(0, sLines[i].IndexOf('=')) + "= new System.Drawing.Icon(\"window.ico\");";
							System.Console.WriteLine("(resources.GetObject(\"...Icon\") string search) Modified line #" + i.ToString());
						}
						else
						{
							sLines[i] = "";
							System.Console.WriteLine("(resources declaration string search) Removed line #" + i.ToString());
						}
					} // end 'Contains("resources")' if
					
				} // end '!Contains("//")' if
				
			} // end for()
			
			
			System.Console.WriteLine("Modification completed, writing to disk...");
			
			
			// Write back to disk...
			DumpFileToDisk("frmDebug.Designer.cs", sLines);
			
			System.Console.WriteLine("Completed.");
			
			
			Console.WriteLine("===========================================");
			Console.WriteLine("  Processing frmDebug.cs ...");
			Console.WriteLine("===========================================");
			
			sLines = System.IO.File.ReadAllText(sDirname + "frmDebug.cs").Replace("\r", "").Split('\n');
			
			for (i = sLines.GetLowerBound(0); i <= sLines.GetUpperBound(0); i++)
			{
				// Need to replace references to ContextMenuStrip...
				if (sLines[i].Contains("ContextMenuStrip") && !sLines[i].Contains("//"))
				{
					if (sLines[i].Contains("notifyIcon.ContextMenuStrip.Show();"))
					{
						sLines[i] = sLines[i].Replace("notifyIcon.ContextMenuStrip", "this");
						System.Console.WriteLine("(Exact notifyIcon.ContextMenuStrip.Show(); string search) Modified line #" + i.ToString());
					}
					else
					{
						sLines[i] = "";
						System.Console.WriteLine("(ContextMenuStrip string search) Removed line #" + i.ToString());
					}
				} // end 'if .. Contains(ContextMenuStrip) && !Contains(//)'
			} // end for()
			
			
			// Now dump to disk again.
			System.Console.WriteLine("Modification completed, writing to disk...");
			DumpFileToDisk("frmDebug.cs", sLines);
			System.Console.WriteLine("Completed.");
			
			
			System.Console.WriteLine("\r\nProgram finished successfully!\r\n");
			
			
		}
		
		
		private static void DumpFileToDisk(string sFilename, string[] sData)
		{
			System.IO.FileStream fs = System.IO.File.OpenWrite(sFilename);
			
			foreach (string s in sData)
				fs.Write(System.Text.Encoding.ASCII.GetBytes(s + "\r\n"), 0, s.Length + 2);
			
			fs.Flush();
			fs.Close();
			fs = null;
		}
		
	}
}
